package cn.itsource.exam.service.impl;

import cn.itsource.exam.domain.StudentRepeat;
import cn.itsource.exam.domain.TeacherType;
import cn.itsource.exam.mapper.StudentRepeatMapper;
import cn.itsource.exam.mapper.TeacherTypeMapper;
import cn.itsource.exam.query.StudentRepeatQuery;
import cn.itsource.exam.query.TeacherTypeQuery;
import cn.itsource.exam.service.IStudentRepeatService;
import cn.itsource.exam.service.ITeacherTypeService;
import cn.itsource.exam.util.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class StudentRepeatServiceImpl implements IStudentRepeatService {

    @Autowired
    private StudentRepeatMapper studentRepeatMapper;


    @Override
    public AjaxResult list(StudentRepeatQuery query) {
        Long count=studentRepeatMapper.selectCountByQuery(query);
        if(count==null){
            return AjaxResult.success();
        }
        List<StudentRepeat> list=studentRepeatMapper.selectByQuery(query);
        Map<String,Object> map=new HashMap<String,Object>();
        map.put("total",count);
        map.put("list",list);
        return AjaxResult.success(map);
    }

    @Override
    public AjaxResult save(StudentRepeat studentRepeat) {
        try {
            studentRepeatMapper.insert(studentRepeat);
            return AjaxResult.success();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("操作失败");
        }
    }

    @Override
    public AjaxResult update(StudentRepeat studentRepeat) {

        try {
            studentRepeatMapper.update(studentRepeat);
            return AjaxResult.success();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("操作失败");
        }
    }

    @Override
    public AjaxResult delete(Long id) {
        try {
            studentRepeatMapper.delete(id);
            return AjaxResult.success();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("操作失败");
        }
    }

    @Override
    public AjaxResult batchDelete(Long[] ids) {
        try {
            studentRepeatMapper.batchDelete(ids);
            return AjaxResult.success();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("操作失败");
        }
    }
}
